package com.hsc.eduservice.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ExcelListener extends AnalysisEventListener<ReadData> {

    List<ReadData> list = new ArrayList<ReadData>();
    @Override
    public void invoke(ReadData readData, AnalysisContext analysisContext) {
        System.out.println("***"+readData);
        list.add(readData);
    }

    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext
            context) {
        System.out.println("表头信息："+headMap);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
    }

    public static void main(String[] args) {
        //实现excel读取操作
        String fileName = "D:\\code\\write.xlsx";
// 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
        EasyExcel.read(fileName, ReadData.class, new ExcelListener()).sheet().doRead();
    }
}
